package xiaoqi.springboot.boot.userService.rpc;

import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;
import xiaoqi.springboot.boot.cn.iocoder.springboot.lab64.userservice.api.*;

@GrpcService
public class UserServiceFrpcImpl extends UserServiceGrpc.UserServiceImplBase {

    @Override
    public void get(UserGetRequest request, StreamObserver<UserGetResponse> responseObserver) {
        UserGetResponse.Builder builder = UserGetResponse.newBuilder();
        builder.setId(request.getId()).setName("没有昵称：" + request.getId()).setGender(request.getId() % 2 + 1);

        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }


    @Override
    public void create(UserCreateRequest request, StreamObserver<UserCreateResponse> responseObserver) {
        UserCreateResponse.Builder builder = UserCreateResponse.newBuilder();
        builder.setId((int) (System.currentTimeMillis()/1000));

        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }
}
